package com.xuyuan.ai.auto;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.openai.OpenAiEmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author xuyuan
 * @desc 创建默认的ChatClient系统，不需要在运行时额外传入Prompt
 * @see org.springframework.ai.chat.client.ChatClient.Builder
 * <p>
 * 使用Builder可以创建默认的ChatClient。
 * defaultOptions(ChatOptions chatOptions)：传入ChatOptions类中定义的可移植选项或特定于模型的选项(例如：OpenAiChatOptions）。有关特定于模型的ChatOptions实现的更多信息，请参阅 JavaDocs。
 * defaultUser(String text)、defaultUser(Resource text)、defaultUser(Consumer<UserSpec> userSpecConsumer)：这些方法允许您定义用户文本。
 * defaultAdvisors(Advisor... advisor)、defaultAdvisors(Consumer<AdvisorSpec> advisorSpecConsumer)：Advisor允许修改用于创建的数据Prompt。该实现通过在提示中附加与用户文本相关的上下文信息QuestionAnswerAdvisor来实现模式。Retrieval Augmented Generation(RAG-检索增强生成)
 * defaultTools(String... toolNames):
 * 也可以在运行时覆盖默认值
 * options(ChatOptions chatOptions)
 * user(String text)
 * advisors(Advisor... advisor)
 */
@Configuration
public class Config {

    @Bean("chatBotChatClient")
    ChatClient chatClient1(ChatClient.Builder builder) {
        return builder.defaultSystem("You are a friendly chat bot that answers question in the voice of a Pirate")
                .build();
    }

    @Bean("voiceChatBotChatClient")
    ChatClient chatClient2(ChatClient.Builder builder) {
        return builder.defaultSystem("You are a friendly chat bot that answers question in the voice of a {voice}")
                .build();
    }

    // @Bean("openAiVectorStore")
    // VectorStore vectorStore(OpenAiEmbeddingModel embeddingModel) {
    //     return SimpleVectorStore.builder(embeddingModel).build();
    // }

    // @Bean
    // ChatMemory chatMemory() {
    //     return new InMemoryChatMemory();
    // }


    // @Bean("advisorChatClient")
    // ChatClient chatClient3(ChatClient.Builder builder, @Qualifier("openAiVectorStore") VectorStore vectorStore, ChatMemory chatMemory) {
    //
    //     return builder
    //             .defaultSystem("""
    //                     You are a customer chat support agent of an airline named "Funnair". Respond in a friendly,
    //                     helpful, and joyful manner.
    //
    //                     Before providing information about a booking or cancelling a booking, you MUST always
    //                     get the following information from the user: booking number, customer first name and last name.
    //
    //                     Before changing a booking you MUST ensure it is permitted by the terms.
    //
    //                     If there is a charge for the change, you MUST ask the user to consent before proceeding.
    //                     """)
    //             .defaultAdvisors(
    //                     new MessageChatMemoryAdvisor(chatMemory), // CHAT MEMORY
    //                     new QuestionAnswerAdvisor(vectorStore), // RAG
    //                     new SimpleLoggerAdvisor())
    //             .build();
    // }

}